************************************************
***Title: weather_association_locations.do
***Creators: Joelle Abramowitz, Shooshan Danagoulian, and Owen Fleming*
***Notes: This file produces a list of each county in the analysis and its R-squared value from the regression of pollen on weather. 

*For questions, contact
*Owen Fleming
*hg3490@wayne.edu
************************************************


**********SETUP
use data/for_analysis, clear

levelsof county
global county_levels = r(levels)

preserve
foreach i in $county_levels {
reg pollen $weather if county == `i' 

scalar r2 = e(r2)
scalar county = `i'
matrix r2_`i' = county , r2
matrix colnames r2_`i' = "county" "r2"
	
}

matrix r2 = . , .
matrix colnames r2 = "county" "r2"
foreach i in $county_levels {
matrix r2 = r2 \ r2_`i'
}

clear
svmat double r2, names(col)
drop if missing(r2)
egen median_r2 = median(r2)
save data/r2, replace
restore

merge m:1 county using data/r2 
drop if missing(r2)
erase data/r2.dta


**********PRODUCE TABLE
keep county countyname r2
duplicates drop
sort r2


**********EXPORT
export excel using results/weather_association_locations, replace



